package chi_example_java;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	
	private Vector<Rental> _rentals = new Vector<Rental>();
	private String _name;
	
	public Customer(String name){
		_name = name;
	}


	public String getName() {
		return _name;
	}
	
	public void addRental(Rental rental) {
		_rentals.addElement(rental);
		
	}
	
	public String statement() {
		String result = "Rental record for " + getName() + ":\n";
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements())
		{
			Rental each = (Rental) rentals.nextElement();
			result += "\t" + each.getMovie().getTitle() + "\t" + Double.toString(each.getCharge()) + "\n";
		}

		result += "Amount owned is " + Double.toString(getTotalCharge()) + "\n";
		result += "You earned " + Integer.toString(getTotalFrequentRenderPoints()) + " frequent renter points";
		return result;
	}
	
	private int getTotalFrequentRenderPoints() {
		int result = 0;
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements())
		{
			Rental each = (Rental) rentals.nextElement();
			result += each.getFrequentPoints();
		}
		return result;
	}
	
	private double getTotalCharge() {
		double result = 0;
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements())
		{
			Rental each = (Rental) rentals.nextElement();
			result += each.getCharge();
		}
		return result;
	}
	


}
